package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.controller.CxBase;
import com.ruoyi.system.domain.SafetyExaminationInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SafetyExaminationPaperInfoMapper;
import com.ruoyi.system.domain.SafetyExaminationPaperInfo;
import com.ruoyi.system.service.ISafetyExaminationPaperInfoService;

/**
 * 试卷信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-04-07
 */
@Service
public class SafetyExaminationPaperInfoServiceImpl extends CxBase implements ISafetyExaminationPaperInfoService
{
    @Autowired
    private SafetyExaminationPaperInfoMapper safetyExaminationPaperInfoMapper;

    /**
     * 查询试卷信息
     * 
     * @param safetyExaminationPaperId 试卷信息ID
     * @return 试卷信息
     */
    @Override
    public SafetyExaminationPaperInfo selectSafetyExaminationPaperInfoById(String safetyExaminationPaperId)
    {
        SafetyExaminationPaperInfo safetyExaminationPaperInfo = safetyExaminationPaperInfoMapper.selectSafetyExaminationPaperInfoById(safetyExaminationPaperId);
        safetyExaminationPaperInfo.setSetDate(StampToString(Long.valueOf(safetyExaminationPaperInfo.getSetDate())));
        return safetyExaminationPaperInfo;
    }

    /**
     * 查询试卷信息列表
     * 
     * @param safetyExaminationPaperInfo 试卷信息
     * @return 试卷信息
     */
    @Override
    public List<SafetyExaminationPaperInfo> selectSafetyExaminationPaperInfoList(SafetyExaminationPaperInfo safetyExaminationPaperInfo)
    {
        startPage();
        List<SafetyExaminationPaperInfo> safetyExaminationPaperInfos = safetyExaminationPaperInfoMapper.selectSafetyExaminationPaperInfoList(safetyExaminationPaperInfo);
        for(SafetyExaminationPaperInfo safetyExaminationPaperInfo1 :safetyExaminationPaperInfos){
            safetyExaminationPaperInfo1.setSetDate(StampToString(Long.valueOf(safetyExaminationPaperInfo1.getSetDate())));
        }
        return safetyExaminationPaperInfos;
    }

    /**
     * 新增试卷信息
     * 
     * @param safetyExaminationPaperInfo 试卷信息
     * @return 结果
     */
    @Override
    public int insertSafetyExaminationPaperInfo(SafetyExaminationPaperInfo safetyExaminationPaperInfo)
    {
        if(!checkNull(safetyExaminationPaperInfo.getSafetyExaminationPaperName())&&!checkNull(safetyExaminationPaperInfo.getSetId())&&!checkNull(safetyExaminationPaperInfo.getQualifiedAmount())){
            if(safetyExaminationPaperInfo.getQualifiedAmount()>0){
                safetyExaminationPaperInfo.setSafetyExaminationPaperId(getIdStamp().toString());
                safetyExaminationPaperInfo.setSetDate(getStamp().toString());
                safetyExaminationPaperInfo.setSafetyExaminationQuestionAmount(0l);
                safetyExaminationPaperInfo.setSafetyExaminationUse(0l);
                return safetyExaminationPaperInfoMapper.insertSafetyExaminationPaperInfo(safetyExaminationPaperInfo);
            }
        }
        return 0;
    }

    /**
     * 修改试卷信息
     * 
     * @param safetyExaminationPaperInfo 试卷信息
     * @return 结果
     */
    @Override
    public int updateSafetyExaminationPaperInfo(SafetyExaminationPaperInfo safetyExaminationPaperInfo)
    {
        if(!checkNull(safetyExaminationPaperInfo.getSafetyExaminationPaperId())&&!checkNull(safetyExaminationPaperInfo.getSafetyExaminationPaperName())&&!checkNull(safetyExaminationPaperInfo.getSetId())&&!checkNull(safetyExaminationPaperInfo.getQualifiedAmount())){
            if(safetyExaminationPaperInfo.getQualifiedAmount()>0) {
                safetyExaminationPaperInfo.setSetDate(getStamp().toString());
                return safetyExaminationPaperInfoMapper.updateSafetyExaminationPaperInfo(safetyExaminationPaperInfo);
            }
        }
        return 0;
    }

    /**
     * 批量删除试卷信息
     * 
     * @param safetyExaminationPaperIds 需要删除的试卷信息ID
     * @return 结果
     */
    @Override
    public int deleteSafetyExaminationPaperInfoByIds(String[] safetyExaminationPaperIds)
    {
        return safetyExaminationPaperInfoMapper.deleteSafetyExaminationPaperInfoByIds(safetyExaminationPaperIds);
    }

    /**
     * 删除试卷信息信息
     * 
     * @param safetyExaminationPaperId 试卷信息ID
     * @return 结果
     */
    @Override
    public int deleteSafetyExaminationPaperInfoById(String safetyExaminationPaperId)
    {
        return safetyExaminationPaperInfoMapper.deleteSafetyExaminationPaperInfoById(safetyExaminationPaperId);
    }
}
